layui.define(['table', 'form'], function(exports){
  var $ = layui.$
      ,admin = layui.admin
      ,view = layui.view
      ,table = layui.table
      ,form = layui.form;

  // 用户
  table.render({
    elem: '#LAY-user-back-manage'
    ,url: '/backstage/userShow' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'用户id', width:100, sort: true, align:'center'}
      ,{field:'username', title:'用户名', align:'center'}
      ,{field:'sex', title:'性别', width:80, align:'center',
        templet: function(d){
          if(d.sex === 0){
            d.sex = "女";
            return d.sex;
          }
          if(d.sex === 1){
            d.sex = "男";
            return d.sex;
          }
          if(d.sex === 2){
            d.sex = "未知";
            return d.sex;
          }
        }
      }
      ,{field:'email', title:'邮箱账号', align:'center'}
      ,{field:'phone', title:'手机号', align:'center'}
      ,{field:'levels', title:'用户级别', sort: true, align:'center',
        templet: function(d){
          if(d.level === 0){
            d.level = "普通用户";
            return d.level;
          }
          if(d.level === 1){
            d.level = "普通会员";
            return d.level;
          }
          if(d.level === 4){
            d.level = "封禁";
            return d.level;
          }
        }
      }
      ,{field:'createTime', title:'创建时间', sort: true, align:'center'}
      ,{field:'vipStartTime', title:'会员开启时间', sort: true, align:'center',
        templet: function(d){
          if(d.level === 0 || d.level === 4){
            d.vipStartTime = "";
            return d.vipStartTime;
          }
          return d.vipStartTime;
        }
      }
      ,{title:'操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
    ]]
    ,text: {
      none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
  });

  // vips
  table.render({
    elem: '#LAY-vips-back-manage'
    ,url: '/backstage/vipsShow' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {field:'id', title:'用户id', width:100, sort: true, align:'center'}
      ,{field:'username', title:'用户名', align:'center'}
      ,{field:'sex', title:'性别', width:80, align:'center',
        templet: function(d){
          if(d.sex === 0){
            d.sex = "女";
            return d.sex;
          }
          if(d.sex === 1){
            d.sex = "男";
            return d.sex;
          }
          if(d.sex === 2){
            d.sex = "未知";
            return d.sex;
          }
        }
      }
      ,{field:'email', title:'邮箱账号', align:'center'}
      ,{field:'phone', title:'手机号', align:'center'}
      ,{field:'levels', title:'用户级别', sort: true, align:'center',
        templet: function(d){
          if(d.level === 1){
            d.level = "普通会员";
            return d.level;
          }
        }
      }
      ,{field:'vipStartTime', title:'会员开启时间', sort: true, align:'center'}
      ,{field:'vipEndTime', title:'会员结束时间', sort: true, align:'center'}
      ,{title:'操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-vipsadmin-admin'}
    ]]
    ,text: {
      none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
  });

  // 订单
  table.render({
    elem: '#LAY-order-back-manage'
    ,url: '/backstage/order/pageLimit' //请求接口
    ,totalRow: true
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {field:'id', title:'id', width:100, sort: true, align:'center', totalRowText: '合计收入'}
      ,{field:'outTradeNo', title:'商品订单号', align:'center'}
      ,{field:'productName', title:'商品名称', align:'center'}
      ,{field:'productType', title:'商品类型', align:'center',
        templet: function(d){
          if(d.productType === 0){
            d.productType = "普通会员";
            return d.productType;
          }
          if(d.productType === 1){
            d.productType = "超级会员";
            return d.productType;
          }
        }
      }
      ,{field:'totalAmount', title:'交易金额', align:'center'}
      ,{field:'status', title:'订单状态', width:80, align:'center',
        templet: function(d){
          if(d.status === 0){
            d.status = "未支付";
            return d.status;
          }
          if(d.status === 2){
            d.status = "支付完成";
            return d.status;
          }
        }
      }
      ,{field:'createTime', title:'创建时间', sort: true, align:'center'}
      ,{field:'updateTime', title:'支付完成时间', sort: true, align:'center',
        templet: function(d){
          if(d.status === 0){
            d.updateTime = "";
            return d.updateTime;
          }
          return d.updateTime;
        }
      }
      ,{field:'sum', title:'收入金额', sort: true, align:'center', totalRow:true,
        templet: function(d){
          if(d.status === 0){
            return 0;
          }
          if(d.status === 2){
            return d.totalAmount;
          }
        }
      }
    ]]
    ,done:function(res){
      var sum =0;//统计收入金额
      layui.each(res.data,function(index,d){
        console.log(d);
        if(d.status === 0){
          sum += 0;
        }
        if(d.status === 2){
          sum += d.totalAmount;
        }
      });
      this.elem.next().find('.layui-table td[data-field="sum"] .layui-table-cell:last').text(sum);
    }
    ,text: {
      none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
  });

  /*function showTime(tempDate) {
    var d = new Date(tempDate);
    var year = d.getFullYear();
    var month = d.getMonth();
    month++;
    var day = d.getDate();
    var hours = d.getHours();

    var minutes = d.getMinutes();
    var seconds = d.getSeconds();
    month = month<10 ? "0"+month:month;
    day = day<10 ? "0"+day:day;
    hours = hours<10 ? "0"+hours:hours;
    minutes = minutes<10 ? "0"+minutes:minutes;
    seconds = seconds<10 ? "0"+seconds:seconds;

    var time = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
    return time;
  }*/

  //  vip
  table.render({
    elem: '#LAY-vip-back-manage'
    ,url: '/backstage/vip/vipShow' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'id', width: 80, title: 'id', sort: true}
      ,{field: 'level', title: '会员等级', align: 'center',
        templet: function(d){
          if(d.level === 0){
            d.level = "普通会员";
            return d.level;
          }
          if(d.level === 1){
            d.level = "超级会员";
            return d.level;
          }
        }
      }
      ,{field: 'capacity', title: '容量/G', align: 'center'}
      ,{field: 'price', title: '会员价格/月', align: 'center'}
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-vipadmin-admin'}
    ]]
      ,text: {
          none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
      }
  });

  //  文件
  table.render({
    elem: '#LAY-file-back-manage'
    ,url: '/backstage/file/pageLimit' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'id', width: 80, title: 'id', sort: true}
      ,{field: 'name', title: '文件名', align: 'center'}
      ,{field: 'md5', title: 'md5', align: 'center'}
      ,{field:'fileSize', title:'文件大小/KB', sort: true, align:'center'}
      ,{field: 'fileType', title: '文件类型', align: 'center'}
      ,{field: 'belongType', title: '所属类型', align: 'center'}
      ,{field:'createTime', title:'文件上传时间', sort: true, align:'center'}
      ,{field:'updateTime', title:'修改时间', sort: true, align:'center'}
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-fileadmin-admin'}
    ]]
    ,text: {
      none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
  });

  //删除文件
  table.on('tool(LAY-file-back-manage)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除此文件？', function(index){
        var id = data.id;
        console.log(id);
        //这里发送ajax请求
        $.ajax({
          url:'/backstage/file/deleteFile',
          dataType:'json',
          data:{'id':id},
          success:function (info) {
            if (info.code=="200"){
              // obj.del();
              layui.table.reload('LAY-file-back-manage'); //重载表格
              layer.msg("删除成功");
              layer.close(index);
            }else {
              layer.alert("删除失败.");
              layer.close(index);
            }
          }
        })
      });
    }
  });

  //  系统消息
  table.render({
    elem: '#LAY-inform-back-manage'
    ,url: '/backstage/inform/pageLimit' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'id', width: 80, title: 'id', sort: true}
      ,{field: 'title', title: '消息标题', align: 'center'}
      ,{field: 'content', title: '消息内容', align: 'center'}
      ,{field:'createTime', title:'创建时间', sort: true, align:'center'}
      ,{field: 'type', title: '消息类型', align: 'center'}
      ,{field:'status', title:'接收对象', sort: true, align:'center',
        templet: function(d){
          if(d.status === 0){
            d.status = "所有用户";
            return d.status;
          }
        }
      }
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-informadmin-admin'}
    ]]
    ,text: {
      none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
  });

  //删除系统消息
  table.on('tool(LAY-inform-back-manage)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除此消息？', function(index){
        var id = data.id;
        console.log(id);
        //这里发送ajax请求
        $.ajax({
          url:'/backstage/inform/deleteInform',
          dataType:'json',
          data:{'id':id},
          success:function (info) {
            if (info.code=="200"){
              // obj.del();
              layui.table.reload('LAY-inform-back-manage'); //重载表格
              layer.msg("删除成功");
              layer.close(index);
            }else {
              layer.alert("删除失败.");
              layer.close(index);
            }
          }
        })
      });
    }
  });

  //删除用户
  table.on('tool(LAY-user-back-manage)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除此角色？', function(index){
        var id = data.id;
        console.log(id);
        //这里发送ajax请求
        $.ajax({
          url:'/backstage/deleteUser',
          dataType:'json',
          data:{'id':id},
          success:function (info) {
            if (info.code=="200"){
              // obj.del();
              layui.table.reload('LAY-user-back-manage'); //重载表格
              layer.msg("删除成功");
              layer.close(index);
            }else {
              layui.table.reload('LAY-user-back-manage'); //重载表格
              layer.alert("删除失败.");
              layer.close(index);
            }
          }
        })
      });
    }else if(obj.event === 'edit'){
      var id = data.id;
      console.log(id);   //当前编辑的人员的id
      admin.popup({
        title: '编辑'
        ,area: ['420px', '450px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/userform', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');
            //$('#email').val(data.email);
            $('#phone').val(data.phone);
            //监听提交
            form.on('submit(LAY-user-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
              //var email = field.email;
              var phone = field.phone;
              var sex = field.sex;
              var level = field.level;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/backstage/updateUser',
                data:{"id":id,"phone":phone, "sex":sex,"level":level},
                dataType:'json',
                success:function (info) {
                  console.log(info);
                  if (info.code=="200"){
                    layui.table.reload('LAY-user-back-manage'); //重载表格
                    layer.close(index); //执行关闭
                  }else if(info.code=="404"){
                    layer.alert("该用户已经被封禁");
                    layer.close(index); //执行关闭
                  }else{
                     layer.alert("修改失败");
                     layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });

  table.render({
    elem: '#manager-table'
    ,url: '/managerShow' //实际需求路径
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
    ,cols: [[
      {field:'rootId', title: 'ID', sort: true, minWidth: 50, align: 'center'}
      ,{field:'rootUsername', title: '管理员名',width: '25%', minWidth: 50, align: 'center'}
      ,{field:'rootTime', title: '上次登录时间' ,width: '25%', minWidth: 50, align: 'center'}
      ,{field:'status', title: '状态' ,width: '25%', minWidth: 50, align: 'center'}
      ,{title:'操作', width: 150, align: 'center',width: '20%', fixed: 'right', toolbar: '#table-manageradmin-admin'}
    ]]
  });

  //修改管理员
  table.on('tool(manager-table)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'edit'){
      var rootId = data.rootId;
      console.log(rootId);   //当前编辑的人员的id
      admin.popup({
        title: '编辑'
        ,area: ['420px', '250px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/managerform', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');

            //监听提交
            form.on('submit(LAY-user-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
              var status = field.status;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/updateById',
                data:{"rootId":rootId,"status":status},
                dataType:'json',
                success:function (info) {
                  console.log(info);
                  if (info.code=="200"){
                    layui.table.reload('manager-table'); //重载表格
                    layer.alert("修改成功");
                    layer.close(index); //执行关闭
                  }else{
                    layer.alert("修改失败")
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });

  //修改会员
  table.on('tool(LAY-vips-back-manage)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'edit'){
      var id = data.id;
      console.log(id);   //当前编辑的人员的id
      admin.popup({
        title: '编辑'
        ,area: ['420px', '450px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/vipsform', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');
            //$('#email').val(data.email);
            $('#phone').val(data.phone);
            $('#vipEndTime').val(data.vipEndTime);
            //监听提交
            form.on('submit(LAY-vips-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
              //var email = field.email;
              var phone = field.phone;
              var vipEndTime = field.vipEndTime;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/backstage/updateVips',
                data:{"id":id,"phone":phone, "vipEndTime":vipEndTime},
                dataType:'json',
                success:function (info) {
                  console.log(info);
                  if (info.code=="200"){
                    layui.table.reload('LAY-vips-back-manage'); //重载表格
                    layer.alert("修改成功");
                    layer.close(index); //执行关闭
                  }else if(info.code=="404"){
                    layer.alert("会员结束时间不得早于会员开启时间");
                    layer.close(index); //执行关闭
                  }else{
                    layer.alert("修改失败");
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });

  //删除vip
  table.on('tool(LAY-vip-back-manage)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除此信息？', function(index){
        var id = data.id;
        console.log(id);
        //这里发送ajax请求
        $.ajax({
          url:'/backstage/vip/deleteVip',
          dataType:'json',
          data:{'id':id},
          success:function (info) {
            if (info.code=="200"){
              // obj.del();
              layui.table.reload('LAY-vip-back-manage'); //重载表格
              layer.msg("删除成功");
              layer.close(index);
            }else {
              layui.table.reload('LAY-vip-back-manage'); //重载表格
              layer.alert("删除失败.");
              layer.close(index);
            }
          }
        })
      });
    }else if(obj.event === 'edit'){
      var id = data.id;
      console.log(id);   //当前编辑的人员的id
      admin.popup({
        title: '编辑'
        ,area: ['420px', '350px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/vipform', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');
            $('#capacity').val(data.capacity);
            $('#price').val(data.price);
            //监听提交
            form.on('submit(LAY-vip-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
              var level = field.level;
              var capacity = field.capacity;
              var price = field.price;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/backstage/vip/updateVip',
                data:{"id":id,"level":level,"capacity":capacity, "price":price},
                dataType:'json',
                success:function (info) {
                  console.log(info);
                  if (info.code=="200"){
                    layui.table.reload('LAY-vip-back-manage'); //重载表格
                    layer.close(index); //执行关闭
                  }else{
                    layer.alert("修改失败");
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });

  // 删除导游
  table.on('tool(LAY-user-back-manage1)', function(obj){
    var data = obj.data;

    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        var tourId = data.tourId;
        console.log(tourId);
        //这里发送ajax请求，删除相应的角色
        $.ajax({
          url:'/stone/tour/deleteTour',
          data:{'tourId':tourId},
          dataType:'json',
          success:function (info) {
            if (info.code==200){
              obj.del();
              layer.close(index);
            }else {
              layer.alert("删除失败.");
            }
          }
        })
        obj.del();
        layer.close(index);
      });
    }else if(obj.event === 'edit'){
      admin.popup({
        title: '添加新角色'
        ,area: ['500px', '480px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/tourform', data).done(function(){
            form.render(null, 'layuiadmin-form-role');

            //监听提交
            form.on('submit(LAY-user-role-submit)', function(data){

              var field = data.field; //获取提交的字段

              //提交 Ajax 成功后，关闭当前弹层并重载表格
              //$.ajax({});
              layui.table.reload('LAY-user-back-role'); //重载表格
              layer.close(index); //执行关闭
            });
          });
        }
      });
    }
  });

  //  线路管理
  table.render({
    elem: '#LAY-user-back-manage2'
    ,url: '/stone/line/lineShow' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'lineId', title: 'ID', width:80, sort: true, fixed: 'left', totalRowText: '合计：'}
      ,{field: 'lineName', title: '线路名'}
      ,{field: 'lineStart', title: '出发地',  sort: true, totalRow: true}
      ,{field: 'lineEnd', title: '目的地',  sort: true}
      //,{field: 'tourId', title: '导游',  sort: true, totalRow: true}
      ,{field: 'money', title: '费用', }
      ,{field: 'transName', title: '交通工具', }
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
    ]]
    ,text: '对不起，加载出现异常！'
  });
  //线路管理
  table.on('tool(LAY-user-back-manage2)', function(obj){
    var data = obj.data;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        var sellId = data.sellId;
        console.log(sellId);
        //这里发送ajax请求
        $.ajax({
          url:'/stone/line/deleteLine',
          dataType:'json',
          data:{'lineId':lineId},
          success:function (info) {
            if (info.code==200){
              // obj.del();
              layui.table.reload('LAY-user-back-manage2'); //重载表格
              layer.msg("删除成功");
              layer.close(index);
            }else {
              layui.table.reload('LAY-user-back-manage2'); //重载表格
              layer.alert("删除失败.");
              layer.close(index);
            }
          }
        })

      });
    }else if(obj.event === 'edit'){
      var lineId = data.lineId;
      console.log(lineId);   //当前编辑的线路的id
      admin.popup({
        title: '编辑'
        ,area: ['420px', '450px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/editLine', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');
            //监听提交
            form.on('submit(LAY-user-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
             var lineName = field.name;
             var start = field.start;
             var end = field.end;
             var money = field.money;
             var trans = field.trans;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/stone/line/updateLine',
                data:{'lineId':lineId,'lineName':lineName,
                'lineStart':start,'lineEnd':end,'money':money,'transName':trans},
                dataType:'json',
                success:function (info) {
                  if (info.code==200){
                    layui.table.reload('LAY-user-back-manage2'); //重载表格
                    layer.close(index); //执行关闭
                  }else{
                    layer.alert("修改失败")
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });



  //  团
  table.render({
    elem: '#LAY-user-back-manage4'
    ,url: '/stone/sth/sthShow' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 3 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      //{type: 'checkbox', fixed: 'left'}
      {field: 'sthId', width: 80, title: 'ID', sort: true}
      ,{field: 'sthTotal', title: '最大人数'}
      ,{field: 'sthName', title: '团名'}
      ,{field: 'sthStarttime', title: '开始时间'}
      ,{field: 'sthMin', title: '最小成团人数'}
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
    ]]
    ,text: '对不起，加载出现异常！'
  });


  table.on('tool(LAY-user-back-manage4)', function(obj){
    var data = obj.data;
    var sthId;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        var sellId = data.sellId;
        console.log(sellId);
        //这里发送ajax请求
      });
    }else if(obj.event === 'edit'){
      var lineId = data.lineId;
      console.log(lineId);   //当前编辑的线路的id


      admin.popup({
        title: '编辑'
        ,area: ['420px', '450px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/administrators/addHodometer', data).done(function(){
            form.render(null, 'layuiadmin-form-admin');
            //监听提交
            form.on('submit(LAY-user-back-submit)', function(data){
              var field = data.field; //获取提交的字段
              console.log(field);
              sthId = field.sthId;
              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url:'/stone/line/updateLine',
                data:{'lineId':lineId,'lineName':lineName,
                  'lineStart':start,'lineEnd':end,'money':money,'transName':trans},
                dataType:'json',
                success:function (info) {
                  if (info.code==200){
                    layui.table.reload('LAY-user-back-manage2'); //重载表格
                    layer.close(index); //执行关闭
                  }else{
                    layer.alert("修改失败")
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });

//行程
  table.render({
    elem: '#LAY-user-back-manage7'
    ,url: '/stone/hodometer/selectAll' //请求接口
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      //,curr: 5 //设定初始在第 5 页
      ,groups: 2 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {field: 'hodometerId', width: 80, title: 'ID', sort: true}
      ,{field: 'hodometerDate', title: '天数'}
      ,{field: 'hodometerLine', title: '线路'}
      ,{field: 'eat', title: '餐饮'}
      ,{field: 'sleep', title: '住宿'}
      ,{field: 'sthId', title: '团队标号'}
      ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
    ]]
    ,text: '对不起，加载出现异常！'
  });

  table.on('tool(LAY-user-back-manage7)', function(obj){
    var data = obj.data;
   var hodometerLine = data.hodometerLine;
    var hodometerId = data.hodometerId;
    window.PartitionId=hodometerLine;
    console.log(data);
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        var sellId = data.sellId;
        console.log(sellId);
        //这里发送ajax请求
      });
    }else {
      if (obj.event !== 'edit') {
        return;
      }
      var lineId = data.lineId;
      console.log(lineId);
      admin.popup({
        title: '编辑'
        , area: ['420px', '450px']
        , id: 'LAY-popup-user-add'
        , success: function (layero, index) {
          view(this.id).render('user/administrators/addHodometer', data).done(function () {
            form.render(null, 'layuiadmin-form-admin');
            //监听提交
            form.on('submit(LAY-user-back-submit)', function (data) {
              var field = data.field; //获取提交的字段
              var meishi = field.meishi;
              var jiudian = field.jiudian;


              //提交 Ajax 成功后，关闭当前弹层并重载表格
              $.ajax({
                url: '/stone/hodometer/updateById',
                data: {
                  'hodometerId': hodometerId,
                 'eat': meishi, 'sleep':jiudian
                },
                dataType: 'json',
                success: function (info) {
                  if (info.code == 200) {
                    layui.table.reload('LAY-user-back-manage7'); //重载表格
                    layer.close(index); //执行关闭
                  } else {
                    layer.alert("修改失败")
                    layer.close(index); //执行关闭
                  }
                }
              });
            });
          });
        }
      });
    }
  });
  exports('useradmin', {})
});